package com.blackitheima.test2;

import java.util.*;

public class MyArray1 {
    public static void main(String[] args) {
        //创建list.of不可变集合
        ArrayList<String> list=new ArrayList<>(List.of("a","b","c","d","e"));
        System.out.println(list);
        //创建Set.of不可变集合
        TreeSet<Integer>ts=new TreeSet<>(Set.of(3,2,1,4,5));
        System.out.println(ts);
        //创建Map.of不可变集合
        HashMap<String,String>hm=new HashMap<>(
                Map.of("小鱼","小花","小明","小红","小鸡","小鸟")
        );
        method1(hm);

        HashMap<String,Integer>hm1=new HashMap<>(
                Map.ofEntries(Map.entry("风雪",23)
                        ,Map.entry("紫雷",21)
                ,Map.entry("狂剑",20))
        );
        method2(hm1);

    }

    private static void method2(HashMap<String, Integer> hm1) {
        //遍历
        Set<Map.Entry<String, Integer>> entries = hm1.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key+"----"+value);
        }
    }

    private static void method1(HashMap<String, String> hm) {
        //遍历
        Set<String> keys = hm.keySet();
        for (String key : keys) {
            String vale = hm.get(key);
            System.out.println(key+"--"+vale);
        }
    }
}
